
package database;

import java.util.logging.Level;
import java.util.logging.Logger;
import logindata.Login;

public class Query {

    private int id;
    private int typeViewable;
    private int category;
    private String content;
    private String createdBy;
    private String responses;

    public Query() {
    }

    public Query(int id, int typeViewable, int category, String createdby,
            String content, String responses) {
        this.id = id;
        this.typeViewable = typeViewable;
        this.category = category;
        this.createdBy = createdby;
        this.content = content;
        this.responses = responses;
    }

    public boolean updateItem(String object, Object data) {
        try {
            if (object.equalsIgnoreCase("typeViewable")) {
                typeViewable = Integer.parseInt(data.toString());
            } else if (object.equalsIgnoreCase("category")) {
                category = Integer.parseInt(data.toString());
            } else if (object.equalsIgnoreCase("createdBy")) {
                createdBy = data.toString();
            } else if (object.equalsIgnoreCase("content")) {
                content = data.toString();
            } else if (object.equalsIgnoreCase("responses")) {
                responses = data.toString();
            } else if (object.equalsIgnoreCase("id")) {
                id = Integer.parseInt(data.toString());
            } else {
                Exception e = new Exception("Type is not in Category.");
                throw e;
            }
            return true;
        } catch (Exception e) {
            Logger lgr = Logger.getLogger(Login.class.getName());
            lgr.log(Level.SEVERE, e.getMessage(), e);
        } finally {
            return false;
        }
    }

    public Object get(String object) {
        Object o;
        try {
            if (object.equalsIgnoreCase("typeViewable")) {
                return typeViewable;
            } else if (object.equalsIgnoreCase("category")) {
                return category;
            } else if (object.equalsIgnoreCase("createdBy")) {
                return createdBy;
            } else if (object.equalsIgnoreCase("content")) {
                return content;
            } else if (object.equalsIgnoreCase("responses")) {
                return responses;
            } else if (object.equalsIgnoreCase("id")) {
                return id;
            } else {
                Exception e = new Exception("Type is not in Category.");
                throw e;
            }
        } catch (Exception e) {
            Logger lgr = Logger.getLogger(Login.class.getName());
            lgr.log(Level.SEVERE, e.getMessage(), e);
            return "ERR";
        }
    }
}
